import vue from '@vitejs/plugin-vue'
import UnoCSS from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import {TDesignResolver} from 'unplugin-vue-components/resolvers';
import {VueHooksPlusResolver} from '@vue-hooks-plus/resolvers'
import * as path from "path";
import {type ConfigEnv, loadEnv, type UserConfig} from "vite";

// https://vite.dev/config/
export default ({mode}: ConfigEnv): UserConfig => {
    const env = loadEnv(mode, process.cwd());
    return {
        base: env.VITE_BASE_PATH,
        server: {
            host: '0.0.0.0',
            port: 5174,
            proxy: {
                '/api': {
                    target: 'http://127.0.0.1:18989/',
                    ws: true,
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api/, '')
                },
            }
        },
        plugins: [
            vue(),
            UnoCSS(),
            AutoImport({
                imports: ['vue', 'vue-router'],
                include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/, /\.md$/],
                dts: 'auto-imports.d.ts',
                resolvers: [
                    VueHooksPlusResolver(),
                    TDesignResolver({
                        library: 'vue-next'
                    })],
            }),
            Components({
                dts: 'components.d.ts',
                resolvers: [TDesignResolver({
                    library: 'vue-next'
                })],
            }),
        ],
        resolve: {
            alias: {
                '@': path.resolve(__dirname, 'src')
            }
        }
    }
}
